package MOLE.sms2;

import MOLE.*;

/** 
 balance ��ժҪ˵����
*/
public class balance
{

	public int Uid;
	public int Money;


	public static DataTable Look(int uid)
	{
	  String sql = "select * from sms_Account    where uid=" + uid;
		DataTable d = MOLE.SQL.GetDataTable(sql);
		return d;

	}

	public final boolean IsHasAccount()
	{
		 DataTable d = Look(Uid);
		if (d.Rows.size() == 0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	public final boolean NewAccount()
	{
		MOLE.SQL_DBOS o = new SQL_DBOS("sms_account", "");
		o.add("uid", Uid);
		o.Add();
		return true;
	}

	public final boolean CHARGEUP()
	{
		String sql = "update sms_Account  set balance=balance+" + Money + " where uid=" + Uid;
		MOLE.SQL.ExecuteSql(sql);
		return true;
	}

	public final void PAY()
	{
		Money = 0 - Money;
		CHARGEUP();
		//		System.Web.HttpContext.Current.Response.Write(o.Con.ToString()+"yyy");
	}
	//		 
	// 
	public final boolean IS_MONEY_OVER()
	{
		int b = GET_BALANCE();
		if (b < Money) //over
		{
			return true;

		}
		return false;
	}

	//
	public final int GET_BALANCE()
	{
		int i = 0;
		String sql = "select top 1 * from  sms_account  where uid=" + Uid;
		SqlDataReader dr = MOLE.SQL.ExecuteReader(sql);
		while (dr.Read())
		{
			i = Integer.parseInt(dr.getItem("balance").toString().trim());
		}
		return i;
	}

	public final boolean DEL()
	{
		String sql = "delete sms_Account  where uid=" + Uid;
		MOLE.SQL.ExecuteSql(sql);
		return true;
	}
}